﻿/*!
* HTML5 Placeholder jQuery Plugin v1.8
* @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin
* @author Mathias Bynens <http://mathiasbynens.be/>
*/
; (function ($) {

    var isInputSupported = 'placeholder' in document.createElement('input'),
isTextareaSupported = 'placeholder' in document.createElement('textarea');
    if (isInputSupported && isTextareaSupported) {
        $.fn.placeholder = function () {
            return this;
        };
    } else {
        $.fn.placeholder = function () {
            return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
.bind('focus.placeholder', clearPlaceholder)
.bind('blur.placeholder', setPlaceholder)
.trigger('blur.placeholder').end();
        };
    }

    function args(elem) {
        // Return an object of element attributes
        var newAttrs = {},
rinlinejQuery = /^jQuery\d+$/;
        $.each(elem.attributes, function (i, attr) {
            if (attr.specified && !rinlinejQuery.test(attr.name)) {
                newAttrs[attr.name] = attr.value;
            }
        });
        return newAttrs;
    }

    function clearPlaceholder() {
        var $input = $(this);
        if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) {
            if ($input.data('placeholder-password')) {
                $input.hide().next().show().focus();
            } else {
                $input.val('').removeClass('placeholder');
            }
        }
    }

    function setPlaceholder(elem) {
        var $replacement,
$input = $(this),
$origInput = $input,
isInitialized = $input.data('placeholder-init');
        if ($input.val() === '' || (!isInitialized && $input.val() === $input.attr('placeholder'))) {
            if ($input.is(':password')) {
                if (!$input.data('placeholder-textinput')) {
                    try {
                        $replacement = $input.clone().attr({ type: 'text' });
                    } catch (e) {
                        $replacement = $('<input>').attr($.extend(args($input[0]), { type: 'text' }));
                    }
                    $replacement
.removeAttr('name')
.data('placeholder-password', true)
.bind('focus.placeholder', clearPlaceholder);
                    $input
.data('placeholder-textinput', $replacement)
.before($replacement);
                }
                $input = $input.hide().prev().show();
            }
            $input.addClass('placeholder').val($input.attr('placeholder'));
        } else {
            $input.removeClass('placeholder');
        }
        if (!isInitialized) {
            $origInput.data('placeholder-init', true);
        }
    }

    $(function () {
        // Look for forms
        $('form').bind('submit.placeholder', function () {
            // Clear the placeholder values so they don’t get submitted
            var $inputs = $('.placeholder', this).each(clearPlaceholder);
            setTimeout(function () {
                $inputs.each(setPlaceholder);
            }, 10);
        });
    });

    // Clear placeholder values upon page reload
    $(window).bind('unload.placeholder', function () {
        $('.placeholder').val('');
    });

} (jQuery));